using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_ModifyCard : Admin, IRequiresSessionState
{
	private CardBll _card = null;
	private int cardId;
	protected DropDownList Edit_CardType;
	protected TextBox Edit_CardNum;
	protected TextBox Edit_CardPassword;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected TextBox Edit_CardValue;
	protected RangeValidator RangeValidator1;
	protected RequiredFieldValidator RequiredFieldValidator4;
	protected DropDownList Edit_CardValidUnit;
	protected TextBox Edit_CardEndDate;
	protected RequiredFieldValidator RequiredFieldValidator5;
	protected TextBox Edit_CardCoin;
	protected RequiredFieldValidator RequiredFieldValidator2;
	protected RangeValidator RangeValidator2;
	protected TextBox Edit_CardAgent;
	protected Button LinkButton1;
	protected HtmlTable EditTable;
	protected DropDownList Add_CardType;
	protected DropDownList Add_CreateCardType;
	protected TextBox Add_CardQuantity;
	protected RangeValidator rv3;
	protected RequiredFieldValidator rfv1;
	protected HtmlTableRow AutoBat;
	protected TextBox Add_CardNum;
	protected RequiredFieldValidator rfv2;
	protected HtmlTableRow Single1;
	protected TextBox Add_CardPassword;
	protected RequiredFieldValidator rfv3;
	protected HtmlTableRow Single2;
	protected TextBox Add_CardValue;
	protected RequiredFieldValidator rfv4;
	protected RangeValidator rv1;
	protected DropDownList Add_CardValidUnit;
	protected TextBox Add_CardEndDate;
	protected RequiredFieldValidator RequiredFieldValidator6;
	protected TextBox Add_CardCoin;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected RangeValidator rvss;
	protected TextBox Add_CardAgent;
	protected Button InsertButton;
	protected HtmlTable AddTable;
	protected Label CardType;
	protected Label CardNum;
	protected Label CardPassword;
	protected Label CardValue;
	protected Label CardValidUnit;
	protected Label CardEndDate;
	protected Label CardCoin;
	protected Label CardAgent;
	protected HtmlTable showTable;
	private CardBll m_card
	{
		get
		{
			CardBll card;
			if (this._card == null)
			{
				this._card = new CardBll();
				card = this._card;
			}
			else
			{
				card = this._card;
			}
			return card;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		base.Response.Expires = 0;
		this.Edit_CardEndDate.Attributes.Add("onClick", string.Concat(new string[]
		{
			"show_cele_date(",
			this.Edit_CardEndDate.UniqueID,
			",'','',",
			this.Edit_CardEndDate.UniqueID,
			");"
		}));
		this.cardId = Fetch.GetID("CardID");
		string text = Fetch.Get("Action");
		string text2 = text;
		if (text2 != null)
		{
			if (!(text2 == "Add"))
			{
				if (!(text2 == "Modify"))
				{
					if (text2 == "Show")
					{
						this.Show();
					}
				}
				else
				{
					this.Modify();
				}
			}
			else
			{
				this.Add();
			}
		}
	}
	protected void Add()
	{
		if (!base.admin.CheckAdminPower(26))
		{
			base.WriteLog("AddNew", Language.GetAdminMsg("Log/Access", "0"), "Card");
			base.WriteRightErrMsg();
		}
		this.AddTable.Visible = true;
		this.EditTable.Visible = false;
		this.showTable.Visible = false;
		if (!base.IsPostBack)
		{
			this.Add_CardType.Text = "1";
			string str = DateTime.Now.AddDays(1.0).Date.ToString("yyyyMMdd");
			this.Add_CardNum.Text = str + this.MakeOutTradeNo();
			this.Add_CardPassword.Text = this.MakePassword(8);
			this.Add_CreateCardType.Attributes.Add("onchange", "ShowCardType(this.value)");
			this.Add_CardEndDate.Attributes.Add("onClick", string.Concat(new string[]
			{
				"show_cele_date(",
				this.Add_CardEndDate.UniqueID,
				",'','',",
				this.Add_CardEndDate.UniqueID,
				");"
			}));
		}
	}
	protected void Modify()
	{
		if (!base.admin.CheckAdminPower(26))
		{
			base.WriteLog("Modify", Language.GetAdminMsg("Log/Access", "0"), "Card");
			base.WriteRightErrMsg();
		}
		if (this.cardId == 0)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/NotData"), "javascript:{window.close();}");
		}
		this.AddTable.Visible = false;
		this.EditTable.Visible = true;
		this.showTable.Visible = false;
		if (!base.IsPostBack)
		{
			DataTable cardByCardID = this.m_card.GetCardByCardID(this.cardId);
			if (cardByCardID.Rows.Count <= 0)
			{
				this.WriteErrMsg("", Language.GetAdminMsg("Common/NotData"), "javascript:{window.close();}");
			}
			DataRow dataRow = cardByCardID.Rows[0];
			this.Edit_CardType.Text = dataRow["CardType"].ToString();
			this.Edit_CardNum.Text = dataRow["CardNum"].ToString();
			this.Edit_CardPassword.Text = dataRow["CardPassword"].ToString();
			this.Edit_CardCoin.Text = dataRow["CardValidNum"].ToString();
			this.Edit_CardEndDate.Text = dataRow["CardEndDate"].ToString();
			this.Edit_CardValue.Text = dataRow["CardMoney"].ToString();
			this.Edit_CardAgent.Text = dataRow["CardAgentName"].ToString();
			this.Edit_CardValidUnit.Text = dataRow["CardValidUnit"].ToString();
			this.Edit_CardEndDate.Attributes.Add("onClick", string.Concat(new string[]
			{
				"show_cele_date(",
				this.Edit_CardEndDate.UniqueID,
				",'','',",
				this.Edit_CardEndDate.UniqueID,
				");"
			}));
		}
	}
	protected void Show()
	{
		if (!base.admin.CheckAdminPower(26))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Card");
			base.WriteRightErrMsg();
		}
		if (this.cardId == 0)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/NotData"), "javascript:{window.close();}");
		}
		this.AddTable.Visible = false;
		this.EditTable.Visible = false;
		this.showTable.Visible = true;
		if (!base.IsPostBack)
		{
			DataTable cardByCardID = this.m_card.GetCardByCardID(this.cardId);
			if (cardByCardID.Rows.Count <= 0)
			{
				this.WriteErrMsg("", Language.GetAdminMsg("Common/NotData"), "javascript:{window.close();}");
			}
			DataRow dataRow = cardByCardID.Rows[0];
			this.CardType.Text = ((dataRow["CardType"].ToString() == "1") ? Language.Get("Shop/Card/Type1") : Language.Get("Shop/Card/Type0"));
			this.CardNum.Text = dataRow["CardNum"].ToString();
			this.CardPassword.Text = "******";
			this.CardCoin.Text = dataRow["CardValidNum"].ToString();
			this.CardValue.Text = dataRow["CardMoney"].ToString();
			this.CardValidUnit.Text = dataRow["CardValidUnit"].ToString();
			this.CardAgent.Text = dataRow["CardAgentName"].ToString();
			this.CardType.Attributes.Add("onchange", "ShowCardType(this.value)");
			this.CardEndDate.Text = dataRow["CardEndDate"].ToString();
		}
	}
	protected void UpDateCard(object sender, EventArgs e)
	{
		DataTable cardByCardID = this.m_card.GetCardByCardID(this.cardId);
		if (cardByCardID.Rows.Count <= 0)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/NotData"), "javascript:{window.close();}");
		}
		string cardPassword = this.Edit_CardPassword.Text;
		if (this.Edit_CardPassword.Text == "")
		{
			cardPassword = cardByCardID.Rows[0]["CardPassword"].ToString();
		}
		this.m_card.UpdateCard(this.Edit_CardNum.Text, cardPassword, Convert.ToInt32(this.Edit_CardType.SelectedValue), this.Edit_CardAgent.Text, this.Edit_CardCoin.Text, Convert.ToDecimal(this.Edit_CardValue.Text), this.Edit_CardValidUnit.Text, Convert.ToDateTime(this.Edit_CardEndDate.Text), this.cardId);
		base.WriteLog("Modify", Language.GetAdminMsg("Log/ObjectID", this.cardId.ToString()), "Card");
		this.WriteSuccessMsg("", Language.Get("Common/Success"), "Admin_Card.aspx");
	}
	protected void AddCard(object sender, EventArgs e)
	{
		int num = this.m_card.AddCard(Convert.ToInt32(this.Add_CreateCardType.SelectedValue), Convert.ToInt32(this.Add_CardQuantity.Text), this.Add_CardNum.Text, this.Add_CardPassword.Text, Convert.ToInt32(this.Add_CardType.Text), this.Add_CardAgent.Text, this.Add_CardCoin.Text, Convert.ToDecimal(this.Add_CardValue.Text), this.Add_CardValidUnit.Text, Convert.ToDateTime(this.Add_CardEndDate.Text));
		if (Convert.ToInt32(this.Add_CardQuantity.Text) == num)
		{
			base.WriteLog("AddNew", Language.GetAdminMsg("Log/ObjectID", "0"), "Card");
			this.WriteSuccessMsg("", Language.Get("Common/Success"), "Admin_Card.aspx");
		}
		else
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/AddFail", "未知"), "javascript:{window.close();}");
		}
	}
}
